package com.seeyon.apps.demo.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.seeyon.apps.demo.Constants4Demo;
import com.seeyon.apps.demo.po.Demo;
import com.seeyon.ctp.util.DBAgent;
import com.seeyon.ctp.util.FlipInfo;

public class DemoDaoImpl implements DemoDao {
		
	@Override
	public void save(Demo demo) {
		DBAgent.save(demo);
	}
	
	@Override
	public void findDemoList(FlipInfo flipInfo, Integer isDeleted) {
		// 不推荐使用select * from object 或 from object的形式获取全部数据，一定要按需获取，才能保障SQL高效率
		String hql = "select new map(d.id as id,d.title as title,d.remark as remark,d.remarkDate as remarkDate,d.createMember as createMember,d.createTime as createTime) from Demo d where d.deleteFlag=:flag order by d.createTime";
		Map<String, Object> params = new HashMap<>();
		params.put("flag", isDeleted);
		DBAgent.find(hql, params, flipInfo);
	}

	@Override
	public void deleteById(List<Long> ids) {
		String hql = "update Demo set deleteFlag = :flag where id in (:ids)";
		Map<String, Object> params = new HashMap<>();
		params.put("flag", Constants4Demo.deleteFlag.ISDELETED.ordinal());
		params.put("ids", ids);
		DBAgent.bulkUpdate(hql, params);
	}
	
}
